home *** CD-ROM | disk | FTP | other *** search
- // FixStickies.c
- // Fix the message that Twits use when they leave their machines idle in the MacHack
- // machine room with a "Do Not Use" message open on them.
- //
- // 23 Jun 95 Mike Crawford crawford@scruznet.com
- // Look for updates, and my real hack, via anonymous ftp from ftp.scruznet.com, in
- // the directory /users/crawford/public/MacFiles
- //
- // Copyright ©1995 Free Software Foundation. See the file COPYING for details on the license
- // to copy this program and its source code
- //
- // Revision History (most recent first)
- //
- // 23 Jun 95 MDC New today
-
- #include <SetUpA4.h>
- #include <Traps.h>
-
- // State machine values
- #define kIdle 0
- #define kCmdKey 2
- #define kTyping 4
-
- #define Ticks 0x16a
- #define Mouse 0x830
- #define CurApName 0x910
-
- #define FAST_TEST
-
- #ifdef FAST_TEST
- //#define kIdleTime 0x12c
- #define kIdleTime 0x708
- #else
- #define kIdleTime 0xd2f0
- #endif
-
- #define kMsgLen 0x24
-
- pascal void main( void )
- {
-
- asm{
- ; Debugger ; Uncomment this for debugging; set PC to the rts to avoid load
- RecoverHandle
- HLock
- Move.l a0, -(sp)
- DetachResource
- Move.l #0xA970, d0 ; GetNextEvent trap word
- GetToolTrapAddress
- Move.l a0, d0
- Lea @realTrapAddress, a0 ; Can't write to a PC relative offset. Can't imagine why!
- Move.l d0, (a0)
- Move.l #0x4, a1
- Moveq #0x9, d0 ; Hey, Symantec, update your headers!
- dc.w 0xA098 ; _HWPriv FlushCodeCacheRange( @realTrapAddress, 4 )
- ; Flushing whole cache under DR emulator blows out 250k; don't
- ; do it - flush ranges instead
- lea @GetNextEventPatch, a0
- Move.l #0xA970, d0
- SetToolTrapAddress
- rts
-
- ; Data storage
-
- @lastTicks
- dc.l 0x0fffffff
-
- @lastMouse
- dc.l 0x00000000
-
- @saveRts
- dc.l 0x00000000
-
- @evtPtr
- dc.l 0x00000000
-
- @charactersTyped
- dc.w 0x0000
-
- @stateMachine
- dc.w kIdle
-
- @GetNextEventPatch
- Lea @saveRts, a0 ; Stash real return address
- Move.l (sp)+, (a0)
-
- ; (sp) is the event record pointer
- ; 4(sp) is the eventMask
- ; 6(sp) will be the result
-
- Lea @evtPtr, a0
- Move.l (sp), (a0) ; Save pointer to event record
- ; We must do this because GetNextEvent will remove params from stack
-
- dc.w 0x4eb9 ; First word of a JSR to long absolute address
- @realTrapAddress
- dc.l 0x00000000 ; JSR to this address to call real GetNextEvent
-
- ; Now we do a switch off of the current state machine value to either
- ; look at the result of GetNextEvent, or fudge the contents of the EventRecord
-
- Move.w @stateMachine, d0
- Lea @jumpTable, a0
- Adda.w d0, a0
- Jmp (a0)
-
- @jumpTable
- Bra @doIdle
- Bra @doCmdKey
- Bra @doTyping
-
- @doIdle
- ; First we check to see if there is anything but a null event in the EventRecord
- ; extern pascal Boolean GetNextEvent(short eventMask, EventRecord *theEvent)
-
- Move.l @evtPtr, a0
- Tst.w (a0) ; if ( eventPtr->what == nullEvt )
- Beq @isNullEvent
-
- ; In this case we have a real, non-null event. Save the time and mouse
- Lea @lastTicks, a0
- Move.l Ticks, (a0)
- Lea @lastMouse, a0
- Move.l Mouse, (a0)
- Bra @doReturn
-
- @isNullEvent
-
- ; We're idle. Has the mouse moved?
- Lea @lastMouse, a0
- Move.l Mouse, d0
- Cmp.l (a0), d0
- Bne @mouseMoved
-
- ; Has enough time gone by?
-
- Lea @lastTicks, a0
- Move.l (a0), d0
- Add.l #kIdleTime, d0
- Lea Ticks, a0
- Cmp.l (a0), d0
- Bgt @doReturn
-
- @timeGoneBy
- ; Are we in Stickies? The proper way would be to get the process info and look at the creator
- ; But the hack contest has already started
-
- Lea CurApName, a0
- Cmp.l #0x08537469, (a0) ; First four bytes of "\pStickies"
- Bne @doReturn
-
- ; Time to get to work
- Lea @stateMachine, a0
- Move.w #kCmdKey, (a0) ; Next time around we'll do a Select All
- Bra @doReturn
-
- @mouseMoved
- Lea @lastMouse, a0
- Move.l Mouse, (a0)
- Bra @doReturn
-
- @doCmdKey
- ; Here we make the event record into a Command-A
- Move.l @evtPtr, a0
- Move.w #keyDown, (a0) ; evtPtr->what = keyDown
- Move.l #0x00020061, 2(a0) ; evtPtr->message = letter 'A'
- Move.w #0x0180, 0xe(a0) ; Command-A is Select all
- Move.w #0x0100, (sp) ; Set GNE result code to "true"
-
- Lea @stateMachine, a0
- Move.w #kTyping, (a0) ; Next time around we'll start typing
- Lea @charactersTyped, a0 ; Reset keystroke counter
- Clr.w (a0)
-
- Bra @doReturn
-
- @doTyping
- ; Here we make the event record into a typed character
- Move.w @charactersTyped, d0
- Cmp.w #kMsgLen, d0
- Bge @doneTyping
-
- Lea @charactersTyped, a0
- Add.w #1, (a0) ; Increment counter
- Lea @messageStr, a0
- Adda.w d0, a0
- Moveq #0, d0
- Move.b (a0), d0 ; fetch a character
-
- Move.l @evtPtr, a0
- Move.w #keyDown, (a0) ; evtPtr->what = keyDown
- Move.l d0, 2(a0) ; evtPtr->message = next letter (note we have no key code)
- Move.w #0x0000, 0xe(a0) ; No modifiers
- Move.w #0x0100, (sp) ; Set GNE result code to "true"
-
- Bra @doReturn
-
- @doneTyping
- Lea @stateMachine, a0
- Move.w #kIdle, (a0) ; Next time around we'll start typing
- Lea @lastTicks, a0 ; Reset timer
- Move.l Ticks, (a0)
-
- @doReturn
- Move.l @saveRts, a0
- Jmp (a0) ; Return to real caller
- @messageStr
- dc.l 'Plea'
- dc.l 'se f'
- dc.l 'eel '
- dc.l 'free'
- dc.l ' to '
- dc.l 'use '
- dc.l 'this'
- dc.l ' mac'
- dc.l 'hine'
- }
-
-
-
- return;
- }
-
-